#pragma once

#include "elk.h"

#define VOL_ELK_MINALLOC 1024

class CElkVolWrapper
{
	public:
		struct js * m_instance;
		//整个运行时内存,为m_instance的生命周期.
	private:
		CVolMem m_mem;

	public:
		inline_ CElkVolWrapper() { Alloc(VOL_ELK_MINALLOC); }
		inline_ void Alloc(UINT size) { if (size < VOL_ELK_MINALLOC) size = VOL_ELK_MINALLOC; m_instance = js_create(m_mem.Realloc(size), size); }
		inline_ CVolString JsValue2VolString(jsval_t value) { return CVolString(GetWideText(js_str(m_instance, value), CVolMem(), NULL)); }
		inline_ CVolString Eval(const char* js) { return JsValue2VolString(js_eval(m_instance, js, ~0)); }
		inline_ jsval_t Eval2(CVolMem& js) { return js_eval(m_instance, (const char*)js.GetPtr(), (size_t)js.GetSize()); }
		inline_ CVolMem& GetMem() { return m_mem; }
		//inline_ int GetMemUsage() { return js_usage(m_instance); }
};

class CElkValueVolWrapper
{
	public:
		jsval_t m_value;
	
	public:
		inline_ CElkValueVolWrapper() { m_value = NULL; }
};